import request from '@/config/axios'

// 打卡记录数据结构
export interface StudyPunchVO {
  id?: number
  userId?: number
  userName?: string
  punchDate?: string
  studyDuration?: number
  readingPages?: number
  voiceRecordCount?: number
  createTime?: string
  updateTime?: string
}

// 打卡统计数据结构
export interface StudyPunchStatsVO {
  totalPunches: number
  todayPunches: number
  weekPunches: number
  monthPunches: number
}

// 用户打卡历史数据结构
export interface UserPunchHistoryVO {
  punchList: StudyPunchVO[]
  continuousDays: number
  monthPunchDays: number
}

// 查询打卡记录列表
export const getStudyPunchPage = (params: {
  current?: number
  size?: number
  userId?: number
  startDate?: string
  endDate?: string
}) => {
  return request.get({ url: '/api/admin/study-punches', params })
}

// 获取打卡统计数据
export const getStudyPunchStats = () => {
  return request.get({ url: '/api/admin/study-punches/stats' })
}

// 获取用户打卡历史
export const getUserPunchHistory = (userId: number, params?: {
  days?: number
}) => {
  return request.get({ url: `/api/admin/study-punches/users/${userId}/history`, params })
}

// 获取打卡排行榜
export const getPunchRanking = (params?: {
  period?: string
  limit?: number
}) => {
  return request.get({ url: '/api/admin/study-punches/ranking', params })
}

// 获取打卡趋势统计
export const getPunchTrend = (params?: {
  days?: number
}) => {
  return request.get({ url: '/api/admin/study-punches/trend', params })
}

// 删除打卡记录
export const deleteStudyPunch = (id: number) => {
  return request.delete({ url: `/api/admin/study-punches/${id}` })
}